<?php

/* 
 * planning/show-resume.phtml
 */
use RHX\Helper\RHDateTime;
use RHX\Helper\Number;
?>
<?php
// variables
$stats = $this->stats;
$codes = $stats['codes'];
$heures	= $stats['heures'];
$week = $stats['week'];
$employe= $this->employe;
$codec = $this->codec;
$planning = $this->planning;
$dayName = array('lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche');
$dateEntree = new RHDateTime($employe->contrat_debut);
$dataCP = $employe->getDataCP();
?>
<div class="content-body">
    <h5><a href="#" onclick="$('#tab-resume').slideToggle('slow'); return false;">Résumé de la semaine <i class="icon icon-list"></i></a></h5>
    <table class="table table-bordered table-condensed table-striped list-table" id="tab-resume" style="display: none;">
	<tbody>
	    <tr>
		<td class="title">Matricule</td><td><?php echo $employe->getMatricule(true); ?></td>
		<td class="title">Noms</td><td><?php echo $employe->prenom .' ' .$employe->nom1; ?></td>
	    </tr>
	    <tr>
		<td class="title">Date entrée</td><td><?php echo $dateEntree->date('d/m/Y'); ?></td>
		<td class="title">Ancienneté</td><td><?php echo $employe->getAnciennete(true) .' (' .$employe->getAncienneteValue(true) .')'; ?></td>
	    </tr>
	    <tr>
		<td class="title">Nb Jour dispo</td><td><?php echo $dataCP['nb'] ?> jour(s)</td>
		<td class="title">Congé Payé</td><td><?php echo $dataCP['heureFloat'] .' heures' .' (' .$dataCP['paye'] .'€)' ?></td>
	    </tr>
	    <tr>
		<td class="title">Horaire Hebdo</td><td><?php echo $dataCP['hebdo'] ?> heure(s)</td>
		<td class="title">Taux</td><td><?php echo $dataCP['taux'] .' x ' .$dataCP['coef'] .' €' ?></td>
	    </tr>
	</tbody>
    </table>
    <h5><a href="#" onclick="$('#tab-occurence').slideToggle('slow'); return false;">Occurence des codes activités <i class="icon icon-list"></i></a></h5>
    <table class="table table-condensed table-striped list-table" id="tab-occurence" style="display: none;">
	<thead>
	    <tr>
		<td>Code</td>
		<td>Nb</td>
		<td>Total</td>
	    </tr>
	</thead>
	<tbody>
	    <?php foreach ($codes as $code => $value): ?>
	    <?php $libelle = $codec[$code]; ?>
	    <?php $heure = $heures[$code]; ?>
	    <tr>
		<td class="<?php echo $libelle ?>"><?php echo $libelle; ?></td>
		<td><?php echo $value; ?> fois</td>
		<td><?php echo $heure->totalHours() .' (<b>' .Number::frenchFormat(RHDateTime::toFloat($heure->totalHours())) .'</b>)' ?></td>
	    </tr>
	    <?php endforeach; ?>
	</tbody>
    </table>
    <h5><a href="#" onclick="$('#tab-details').slideToggle('slow'); return false;">Heures détaillés par jour  <i class="icon icon-list"></i></a></h5>
    <table class='table table-bordered table-condensed list-table' id="tab-details" style="display: none;">
	<thead>
	    <tr>
		<?php foreach($dayName as $day): ?>
		<td><?php echo $day; ?></td>
		<?php endforeach; ?>
		<td width="15%">Total</td>
	    </tr>
	</thead>
	<tbody>
	    <tr>
		<?php 
		$total = new RHDateTime(); 
		$total->setTime();
		?>
		<?php foreach($dayName as $day): ?>
		<?php 
		$jour = $week[$day];
		$total->addHours($jour->getDiff(false), false);
		?>
		<td><?php echo $jour->getDiff(false) .' (' .$jour->getDiff(true, true) .')'; ?></td>
		<?php endforeach; ?>
		<td><b><?php echo $total->totalHours() .' (' .Number::frenchFormat(RHDateTime::toFloat($total->totalHours())) .')' ?></b></td>
	    </tr>
	    <tr>
		<?php $totalValue = 0.0; ?>
		<?php foreach($dayName as $day): ?>
		<?php 
		$jour = $week[$day];
		?>
		<?php $totalValue += $jour->getValue($dataCP['coef'], $dataCP['taux']); ?>
		<td><?php echo $jour->getValue($dataCP['coef'], $dataCP['taux'], true);?></td>
		<?php endforeach; ?>
		<td><b><?php echo Number::frenchFormat($totalValue); ?></b></td>
	    </tr>
	</tbody>
    </table>
    <h5><a href="#" onclick="$('#tab-heures').slideToggle('slow'); return false;">Heures calculées<i class="icon icon-list"></i></a></h5>
    <table class='table table-bordered table-condensed list-table' id="tab-heures" style="display: none;">
	<tbody>
	    <tr>
		<td style="background: #c1d4dc">Travaillées</td><td><?php echo Number::frenchFormat(RHDateTime::toFloat($total->totalHours())) ?></td>
		<td style="background: #c1d4dc">Prévues</td><td><?php echo Number::frenchFormat($dataCP['hebdo']) ?></td>
		<td style="background: #c1d4dc">Non-Planifiées</td>
		<td>
		    <?php $nonPrevues = (RHDateTime::toFloat($total->totalHours()) - $dataCP['hebdo']); ?>
		    <b><?php echo (($nonPrevues > 0) ? '+' : '') .Number::frenchFormat($nonPrevues) ?></b>
		</td>
	    </tr>
	</tbody>
    </table>
    
    <h5><a href='#' onclick='$("#tab-hnp").slideToggle("slow"); return false;'>Heures non planifiées de la Période <i class="icon icon-list"></i></a></h5>
    <table class='table table-bordered table-condensed list-table hide' id='tab-hnp'>
	<thead>
	    <tr>
		<td></td>
		<?php $i = 1; ?>
		<?php foreach($hnp as $h): ?>
		<td>Sem. <?php echo $i++; ?></td>
		<?php endforeach; ?>
		<td>Total</td>
	    </tr>
	</thead>
	<tbody>
	    <tr>
		<td>Trav.</td>
		<?php $total = 0; ?>
		<?php foreach($hnp as $h): ?>
		<td><?php $total += $h['travaille'];echo $h['travaille'] ?></td>
		<?php endforeach; ?>
		<td><?php echo $total; ?></td>
	    </tr>
	    <tr>
		<td>Prev.</td>
		<?php $total = 0; ?>
		<?php foreach($hnp as $h): ?>
		<td><?php $total += $h['prevues'];echo $h['prevues'] ?></td>
		<?php endforeach; ?>
		<td><?php echo $total; ?></td>
	    </tr>
	    <tr>
		<td>HNP</td>
		<?php $total = 0; ?>
		<?php foreach($hnp as $h): ?>
		<td><?php $total += $h['hnp']; echo $h['hnp']; ?></td>
		<?php endforeach; ?>
		<td><?php echo $total; ?></td>
	    </tr>
	</tbody>
    </table>
    </div>
</div>
<style type="text/css">
    .title{
	font-weight: bold;
	text-decoration: underline;
    }
    .icon-list{
	margin-left: 5px;
    }
    .icon-list:hover{
	box-shadow: 0px 0px 3px 3px #ffdfb3;
    }
    h5{
	border: solid 1px #c7d2d4;
	padding: 1px;
	margin: 3px auto;
    }
    h5 a{
	display: block;
	width: 99%;
	height: 99%;
	margin: auto;
    }
</style>